package ltd.bugs.cute.urm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ltd.bugs.cute.cache.CacheClient;
import ltd.bugs.cute.cache.CacheKeyUtil;
import ltd.bugs.cute.cache.callback.GetCallback;
import ltd.bugs.cute.urm.dao.RoleDAO;
import ltd.bugs.cute.urm.model.Role;

@Service
public class RoleService {

  public static final CacheKeyUtil keyUtil = new CacheKeyUtil(Role.class);
  @Autowired
  private RoleDAO roleDAO;

  public Role get(long id) {
    return CacheClient.get(keyUtil.getRecKey("." + id), new GetCallback<Role>() {

      @Override
      public String getCacheGroup() {
        return null;
      }

      @Override
      public Role getObject() {
        return roleDAO.get(id);
      }
    });
  }
}
